Smart Buttons
Controls/XML Elements
JavaScript Snippets <JsSnippet>
This control consumes JavaScript snippets inside of a Smart Buttons script.
Configuring
You can configure JsSnippet by entering the JavaScript in the JavaScript Snippet XML Generator.
To configure with the JavaScript Snippet XML Generator:
-
Open the Smart Buttons Editor to create a script.
-
Click JavaScript snippet <JsSnippet> to display the JavaScript Snippet XML Generator.
-
Enter the Variable name.
-
Optional. In Optional script URLs, enter the URL to load a JavaScript script and click the Plus icon.
Tip! You can also add a URL using the ScriptsUrls element.
-
Enter the JavaScript code.
Click Test snippet to perform the function.
-
Click Submit.
Executing
All variables from the script are available in JavaScript execution context. <JsSnippet> returns the text/string value back to the Smart Buttons script (into provided 'VarName'), which can then be consumed by other XML elements in Smart Buttons.
For example, the JavaScript snippet Var: TextToDisplay is returned and the value is displayed in the ShowMessage XML element.
Multiple Variables
It is also possible to return multiple variables back into XML executable context in the form of a JSON object (JSON property => 'VarName', JSON property value => 'VarName' value ).
For example:
<ButtonConf ButtonName="Return multiple vars" Description="" QuickCommand="">
<JsSnippet VarName="">
<Code><![CDATA[
return {
Costcenter: '128739',
CustomerNumber: 87979
};
]]></Code>
</JsSnippet>
<ShowMessage>[Costcenter], [CustomerNumber]</ShowMessage>
</ButtonConf>